package com.kaishengit.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kaishengit.dao.CityDao;
import com.kaishengit.dao.CountryDao;
import com.kaishengit.dao.RegionDao;
import com.kaishengit.dao.StateDao;
import com.kaishengit.pojo.City;
import com.kaishengit.pojo.Country;
import com.kaishengit.pojo.Region;
import com.kaishengit.pojo.State;

@Service
@Transactional
public class AddressService {
	
	@Autowired
	private CountryDao countryDao;
	
	@Autowired
	private StateDao stateDao;
	
	@Autowired
	private CityDao cityDao;
	
	public List<State> findStateById(int id) {
		
		Country country = countryDao.findByUnique("id", id);
		
		List<State> states = country.getStates();
		
		return states;
	}

	public List<City> findCityById(int id) {
		
		State state = stateDao.findByUnique("id", id);
		List<City> cities = state.getCities();
		
		return cities;
	}

	public List<Region> findRegionById(int id) {
		
		City city = cityDao.findByUnique("id", id);
		List<Region> regions = city.getRegions();
		
		return regions;
	}
	
}
